/**
 * Created by bgy on 2016/12/2.
 */
import React from 'react';
import {Link} from 'react-router';
import AttachmentMgt from '../common/AttachmentMgtNew';

var GysData = React.createClass({
  getInitialState(){
    let picUploadParam = [
      {
        "appKey": "b2b",
        "ownType": "supplier",
        "ownCode": "",//供应商编号
        "fileUseCode": "businessLicense",//营业执照
        "fmFiles": [
          {
            "fileId": "",
            "appKey": "b2b",
            "ownType": "supplier",
            "ownCode": "",
            "fileUseCode": "businessLicense",
            "fileUseLabel": "营业执照",
            "fileKey": "",
            "bucketName": "private"
          }
        ]
      },{
        "appKey": "b2b",
        "ownType": "supplier",
        "ownCode": "",//供应商编号
        "fileUseCode": "taxRegistrationCertificate",//税务登记证
        "fmFiles": [
          {
            "fileId": "",
            "appKey": "b2b",
            "ownType": "supplier",
            "ownCode": "",
            "fileUseCode": "taxRegistrationCertificate",
            "fileUseLabel": "税务登记证",
            "fileKey": "",
            "bucketName": "private"
          }
        ]
      },{
        "appKey": "b2b",
        "ownType": "supplier",
        "ownCode": "",//供应商编号
        "fileUseCode": "dutyFreeCertificate",//免税证明
        "fmFiles": [
          {
            "fileId": "",
            "appKey": "b2b",
            "ownType": "supplier",
            "ownCode": "",
            "fileUseCode": "dutyFreeCertificate",
            "fileUseLabel": "免税证明",
            "fileKey": "",
            "bucketName": "private"
          }
        ]
      },{
        "appKey": "b2b",
        "ownType": "supplier",
        "ownCode": "",//供应商编号
        "fileUseCode": "identityCardFront",//身份证前面
        "fmFiles": [
          {
            "fileId": "",
            "appKey": "b2b",
            "ownType": "supplier",
            "ownCode": "",
            "fileUseCode": "identityCardFront",
            "fileUseLabel": "身份证前面",
            "fileKey": "",
            "bucketName": "private"
          }
        ]
      },{
        "appKey": "b2b",
        "ownType": "supplier",
        "ownCode": "",//供应商编号
        "fileUseCode": "identityCardBack",//身份证后面
        "fmFiles": [
          {
            "fileId": "",
            "appKey": "b2b",
            "ownType": "supplier",
            "ownCode": "",
            "fileUseCode": "identityCardBack",
            "fileUseLabel": "身份证后面",
            "fileKey": "",
            "bucketName": "private"
          }
        ]
      }
    ];
    return {picUploadParam: picUploadParam};
  },
  onChildChanged: function (code, res) {
    let picUploadParam = this.state.picUploadParam;
    for (let i = 0; i < picUploadParam.length; i++) {
      if (picUploadParam[i].fileUseCode == code) {
        picUploadParam[i].fmFiles[0].fileKey = res[0];
        break;
      }
    }
    this.state.picUploadParam = picUploadParam;
  },
  submit: function () {

    let vendorNameObj = this.refs.vendorName;
    let organizationCodeObj = this.refs.organizationCode;
    let cardNoObj = this.refs.cardNo;

    let vendorName = vendorNameObj ? vendorNameObj.value : '';//公司名称
    let organizationCode = vendorNameObj ? organizationCodeObj.value : '';//组织机构代码
    let cardNo = cardNoObj ? cardNoObj.value : '';//身份证号

    let picUploadParam = this.state.picUploadParam;
    window.localStorage.setItem('picUploadParam', JSON.stringify(picUploadParam));

    this.props.submitForm(vendorName, organizationCode,cardNo);
  },
  render: function () {
    var type = this.props.customerKind;
    if (type == 'E') {
      return (
        <div>
          <div className="form-item">
            <label htmlFor="">公司名称</label><input type="text" ref='vendorName' placeholder="请输入公司名称"/>
          </div>
          <div className="form-item">
            <label htmlFor="">组织机构代码</label><input type="text" ref='organizationCode' placeholder="请输入组织机构代码"/>
          </div>
          <div className="form-item pic">
            <label htmlFor="">个体营业执照</label>
            <AttachmentMgt addButtonSrc='images/uploadPic.png' allowMultiple={false} bucketname="private" callbackParent={this.onChildChanged.bind(this,'businessLicense')}></AttachmentMgt>
          </div>
          <div className="form-item pic">
            <label htmlFor="">税务登记证</label>
            <AttachmentMgt addButtonSrc='images/uploadPic.png' allowMultiple={false} bucketname="private" callbackParent={this.onChildChanged.bind(this,'taxRegistrationCertificate')}></AttachmentMgt>
          </div>
          <div className="form-item last">`
            <input onClick={this.props.ensureAgreement} type="radio"/>
            <a href="http://www.baidu.com" className="left link">同意 《百果园采购协议》</a>
          </div>
          <button className="button button-pill button-primary btn-green btn-long" disabled={this.props.submitBtnDisabled} onClick={this.submit}>提交</button>
        </div>
      )
    } else if (type == 'F') {
      return (
        <div>
          <div className="form-item">
            <label htmlFor="">组织名称</label><input type="text" ref='vendorName' placeholder="请输入组织名称"/>
          </div>
          <div className="form-item">
            <label htmlFor="">组织机构代码</label><input type="text" ref='organizationCode' placeholder="请输入组织机构代码"/>
          </div>
          <div className="form-item pic">
            <label htmlFor="">个体户营业执照</label>
            <AttachmentMgt addButtonSrc='images/uploadPic.png' allowMultiple={false} bucketname="private" callbackParent={this.onChildChanged.bind(this,'businessLicense')}></AttachmentMgt>
          </div>
          <div className="form-item pic">
            <label htmlFor="">税务登记证</label>
            <AttachmentMgt addButtonSrc='images/uploadPic.png' allowMultiple={false} bucketname="private" callbackParent={this.onChildChanged.bind(this,'taxRegistrationCertificate')}></AttachmentMgt>
          </div>
          <div className="form-item pic">
            <label htmlFor="">免税证明</label>
            <AttachmentMgt addButtonSrc='images/uploadPic.png' allowMultiple={false} bucketname="private" callbackParent={this.onChildChanged.bind(this,'dutyFreeCertificate')}></AttachmentMgt>
          </div>
          <div className="form-item last">
            <input onClick={this.props.ensureAgreement} type="radio"/>
            <a style={{justifyContent:'flex-start'}} href="http://www.baidu.com" className="left link">同意 《百果园采购协议》</a>
          </div>
          <button className="button button-pill button-primary btn-green btn-long" disabled={this.props.submitBtnDisabled} onClick={this.submit} >提交</button>
        </div>
      )
    } else if (type == 'G') {
      return (
        <div>
          <div className="form-item">
            <label htmlFor="">公司名称</label><input type="text" ref='companyName' placeholder="请输入公司名称"/>
          </div>
          <div className="form-item">
            <label htmlFor="">组织机构代码</label><input type="text" ref='organizationCode' placeholder="请输入组织机构代码"/>
          </div>
          <div className="form-item pic">
            <label htmlFor="">个体户营业执照</label>
            <AttachmentMgt addButtonSrc='images/uploadPic.png' allowMultiple={false} bucketname="private" callbackParent={this.onChildChanged.bind(this,'businessLicense')}></AttachmentMgt>
          </div>
          <div className="form-item pic">
            <label htmlFor="">税务登记证</label>
            <AttachmentMgt addButtonSrc='images/uploadPic.png' allowMultiple={false} bucketname="private" callbackParent={this.onChildChanged.bind(this,'taxRegistrationCertificate')}></AttachmentMgt>
          </div>
          <div className="form-item last">
            <input onClick={this.props.ensureAgreement} type="radio"/>
            <a href="http://www.baidu.com" className="link">同意 《百果园采购协议》</a>
          </div>
          <button className="button button-pill button-primary btn-green btn-long" disabled={this.props.submitBtnDisabled} onClick={this.submit} >提交</button>
        </div>
      )
    } else if (type == 'H') {
      return (
        <div>
          <div className="form-item">
            <label htmlFor="">身份证号码</label><input type="text" ref='cardNo' placeholder="请输入身份证号码"/>
          </div>
          <div className="form-item pic">
            <label htmlFor="">身份证正面照</label>
            <AttachmentMgt addButtonSrc='images/uploadPic.png' allowMultiple={false} bucketname="private" callbackParent={this.onChildChanged.bind(this,'identityCardFront')}></AttachmentMgt>
          </div>
          <div className="form-item pic">
            <label htmlFor="">身份证背面照</label>
            <AttachmentMgt addButtonSrc='images/uploadPic.png' allowMultiple={false} bucketname="private" callbackParent={this.onChildChanged.bind(this,'identityCardBack')}></AttachmentMgt>
          </div>
          <div className="form-item last">
            <input onClick={this.props.ensureAgreement} type="radio"/>
            <a href="http://www.baidu.com" className="left link">同意 《百果园采购协议》</a>
          </div>
          <button className="button button-pill button-primary btn-green btn-long" disabled={this.props.submitBtnDisabled} onClick={this.submit} >提交</button>
        </div>
      )
    } else {
      return null;
    }
  }
})
export default GysData;
